<?php
/**
 * RequestedFile Class
 *
 * @package Extensions
 * @version @@VERSION@@
 * @subpackage Low-Cal_Vanilla
 * @copyright Damien Lebrun 2007
 * @author Damien Lebrun
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GPLv2
 */

require_once('Class.File.php');

/**
 * RequestedFile Class
 * @package Extensions
 * @subpackage Low-Cal_Vanilla
 */
class LowCalVanilla_FileToServe extends LowCalVanilla_File {
	/**
	 * @var string Mime type of the file
	 */
	var $Mime;
	/**
	 * @var string
	 */
	var $ContentEncoding;


	/**
	 * Constructor
	 * @return void
	 * @param string $Path
	 * @param string $Mime Mime type
	 * @param string $Encoding Content encoding
	 */
	function LowCalVanilla_FileToServe(&$Context, $Path, $Mime = 'text/plain', $Encoding = '') {
		$this->Context = &$Context;
		$this->SetPath($Path);
		$this->SetMime($Mime);
		$this->SetContentEncoding($Encoding);
	}

	/**
	 * Get details of file to set the header
	 * @return array
	 */
	function GetDetails() {
		$Details = array();
		$Details['Expires'] = gmdate(
			'D, d M Y H:i:s',
			time() + ForceInt($this->Context->Configuration['LOWCALVANILLA_EXPIRE'], 3600)) . ' GMT';
		$Details['Last-Modified'] = gmdate('D, d M Y H:i:s', $this->GetLastModification()) . ' GMT';
		$Details['ETag'] = $this->GetLastModification();
		$Details['Content-Type'] = $this->Mime;
		$Details['Content-Length'] = $this->GetSize();
		if ($this->ContentEncoding) {
			$Details['Content-Encoding'] = $this->ContentEncoding;
		}
		return $Details;
	}

	/**
	 * Set Content Encoding
	 * @return void
	 * @param string $ContentEncoding
	 */
	function SetContentEncoding($ContentEncoding) {
		$this->ContentEncoding = $ContentEncoding;
	}

	/**
	 * Set Mime type
	 * @return void
	 * @param string $Mime
	 */
	function SetMime($Mime) {
		$this->Mime = $Mime;
	}
}